package com.feihao.zhou.C3P0Test;

import com.mchange.v2.c3p0.ComboPooledDataSource;


import javax.sql.DataSource;
import java.sql.*;

public class TestC3P0Pool {
    public static void main(String[] args) throws SQLException {
        //1.获取数据库连接池对象
        DataSource dataSource = new ComboPooledDataSource();

        Connection connection = dataSource.getConnection();

        //sql数据:
        String sql = "SELECT * FROM student ";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);

        //执行：
        ResultSet resultSet = preparedStatement.executeQuery();

        while (resultSet.next()) {
            Integer sid = resultSet.getInt("sid");
            String name = resultSet.getString("name");
            Integer age = resultSet.getInt("age");
            Date birthday = resultSet.getDate("birthday");
            System.out.println(sid + " " + name + " " + age + " " + birthday);
        }

        //施放资源：
        resultSet.close();
        connection.close();
        preparedStatement.close();

    }
}
